package com.base.cn.platform.os.common.mybatis.algorithm;

import com.base.cn.platform.os.common.mybatis.sharding.ShardingTableAlgorithm;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.common.utils.StringUtils;

import java.util.Map;

/**
 * 算法实现类
 *
 * @author s.li
 * @date 2019/04/10
 */
public class UserIdShardingTableRuleImpl implements ShardingTableAlgorithm{

    @Override
    public String doSharding(String logicTableName ,  Map<String,Object> shardingValues) {
        if(StringUtils.isNotEmpty(logicTableName) && ObjectUtils.isNotEmpty(shardingValues)){
            Object userId = shardingValues.get("userId");
            return logicTableName+"_"+(String.valueOf(userId).replaceAll("'",""));
        }
        return null;
    }
}
